package org.mybatis3.demo1;

import org.apache.ibatis.session.SqlSession;
import org.mybatis3.demo1.dao.RoleMapper;
import org.mybatis3.demo1.dao.UserMapper;
import org.mybatis3.demo1.pojo.Role;
import org.mybatis3.demo1.pojo.User;
import org.mybatis3.util.MyBatisUtil;

import java.util.List;

public class Test9 {
    public static void main(String[] args) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();

        List<Role> roleList = sqlSession.getMapper(RoleMapper.class).getRolesAndUsers();
        for (int i = 0; i < roleList.size(); i++) {

            System.out.println("角色名称：" + roleList.get(i).getRoleName() );
            List<User> users=roleList.get(i).getUsers();
            for (int j=0;j<users.size();j++){
                System.out.println("     用户名："+users.get(j).getUserName());
            }
        }
        MyBatisUtil.closeSqlSession();
    }
}
